var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var site = "http://www.dfdled.com/"; //结尾带'/'

$(document).ready(function(){
	$.ajax({
		type: "POST",
		url: site+"ajax.php",
		data: "action=cachemod",
		success: function(msg){
			
		}
	});
});

function getcontentcomment(contentid) {
	$.ajax({
			type: "POST",
			url: site+"ajax.php",
			data: "action=getcontentcomment&contentid="+contentid,
			success: function(msg){
				$('#contentcomment').html(msg);
			}
	});
}

function strlen(str) {
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}

function putcontentcomment(form) {
	var message  = contentid = content = vistername= tel= '';
	
	contentid = form.contentid.value;
	vistername = form.vistername.value;
	tel = form.tel.value;
	mail = form.mail.value;
	content = form.content.value;

	if (strlen(content) <= 2 || strlen(content) > 500){
		message = '内容2~500个字数以内。\n';
	}
			
	if(message != '') {
		alert(message);
		return false;
	}
	$.ajax({
		type: "POST",
		url: site+"ajax.php",
		data: "action=putcontentcomment&contentid="+contentid+"&content="+content+"&vistername="+vistername+"&tel="+tel+"&mail="+mail,
		success: function(msg){
			if (msg == 1) {
				alert('您询盘的太快了，坐下来喝杯茶吧。');return false;
			}
			if (msg == 'banned') {
				alert("系统检测到评论内容中包含敏感字符，请改正。");return false;
			}
			if (msg == 'commentban') {
				alert("当前时段禁止评论，请稍后再来。谢谢。");return false;
			}
			if(msg == 2) {
				alert("询盘成功！");
				$('#content').attr("value",'');
				return false;
			}
			if (msg != ''){
				$('#contentcomment').append(msg);
			}
		}
	});

	return false;
}

function updateshopviews(sid)
{
	$.ajax({
		type: "POST",
		url: site+"ajax.php",
		data: "action=updateshopviews&sid="+sid
	});
}

function updatecontentviews(contentid)
{
	$.ajax({
		type: "POST",
		url: site+"ajax.php",
		data: "action=updatecontentviews&contentid="+contentid
	});
}

function loginn(form)
{
	var username = password = mod = '';
	username = form.username.value;
	password = form.password.value;
	mod = form.mod.value;
	if(username == '' || password == '') { alert('请输入用户名和密码'); return false; }
	$.ajax({
		type: "POST",
		url: site+"ajax.php",
		data: "action=login&mod="+mod+"&username="+username+"&password="+password,
		success: function(msg){
			if (msg == -1) {
				alert('用户不存在,或者被删除');return false;
			}
			if (msg == -2) {
				alert("密码错误");return false;
			}
			if (msg != ''){
				$('#loginbox').html(msg);
			}
		}
	});

	return false;
}

function logout(mod)
{
	$.ajax({
		type: "POST",
		url: site+"ajax.php",
		data: "action=logout&mod="+mod,
		success: function(msg){
			if (msg != ''){
				$('#loginbox').html(msg);
				$('#space').html('');
				alert("退出成功");
				return false;
			}
		}
	});
}